﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;
using IHISCETeim.BLL;

namespace IHISCETeim.Web.MachineSys.MacModel
{
    public partial class OCExportXNJCValue : System.Web.UI.Page
    {

        /// <summary>
        /// 机型
        /// </summary>
        protected string MC
        {
            get {
                return Request["mc"].ToString();
            }
        }

        /// <summary>
        /// 获取所有的机器
        /// </summary>
        /// <returns></returns>
        protected Dictionary<string, SerializableDictionary<string, XRJCItem>> GetMacTypeList()
        {
            string SQLWHERE = "machinetype = '" + MC + "'";
            int TotalCount = 0;
            DataTable DT=     OCompletingCheckController.GetPagination(SQLWHERE, 1, 9999999, "CCID DESC", ref TotalCount);
            //所有机器列表
            Dictionary<string, SerializableDictionary<string, XRJCItem>> allMac = new Dictionary<string, SerializableDictionary<string, XRJCItem>>();

            foreach (DataRow dr in DT.Rows)
            {
                int CCID = Convert.ToInt32(dr["CCID"]);
                OCompletingCheckInfo obj = OCompletingCheckController.GetById(CCID);
                SerializableDictionary<string, XRJCItem> _XRJCDict = null;

                _XRJCDict = XmlSerializerHelper.Deserialize<SerializableDictionary<string, XRJCItem>>(obj.XNJCItem);

                foreach (var x in CompleteCheckXMLHelper.XRJCDict)
                {

                    if (!_XRJCDict.ContainsKey(x.Key))
                    {
                        XRJCItem tempitem = new XRJCItem();
                        tempitem.Key = x.Key;
                        tempitem.Value = "";
                        tempitem.NGValue = "OK";
                        _XRJCDict.Add(x.Key, tempitem);
                    }
                }

                //加添机器
                allMac.Add(obj.SerialNumber +"-"+ obj.CCID.ToString(), _XRJCDict);
            }

            return allMac;

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Dictionary<string, SerializableDictionary<string, XRJCItem>> list = GetMacTypeList();
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("SerialNumber"));//机号
            foreach (var x in CompleteCheckXMLHelper.XRJCDict)
            {
                dt.Columns.Add(new DataColumn(x.Key));
            }

            //
            foreach (var itm in list)
            {
                DataRow dr = dt.NewRow();
                dr["SerialNumber"] = itm.Key;

                foreach (var subItm in itm.Value)
                {
                    dr[subItm.Key] = subItm.Value.Value;
                }

                dt.Rows.Add(dr);
            }

            GridView1.DataSource = dt;
            GridView1.DataBind();

        }
    }
}